<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    // 数组的entries
    let arr = ['a', 'b', 'c'];
    let res = arr.entries();
    console.log(res);
    console.log(res.next());
    console.log(res.next());
    console.log(res.next());
    console.log(res.next());
    console.log('-------------------------------');
    </script>
    <script>
    // 实现entries
    Array.prototype.myentries = function() {
        let obj = {
            index: 0,
            length: 0,
            next() {
                if (++this.index > this.length) {
                    return {value: undefined, done: true}
                } else {
                    return {value: [this.index, this[this.index]], done:false}
                }
            },
            // 方便使用for of: 数组对象中values的for of 方法
            [Symbol.iterator]:Array.prototype[Symbol.iterator]
        }
        // 赋值
        for (let i = 0; i < this.length; i++) {
            obj[i] = this[i];
            // 设置length属性
            obj.length++;
        }
        return obj;
    }
    let brr = ['a', 'b', 'c'];
    let res1 = arr.myentries();
    console.log(res1);
    console.log(res1.next());
    console.log(res1.next());
    console.log(res1.next());
    console.log(res1.next());
    // for (let item of res1) {
    //     console.log(item);
    // }
    </script>
</body>
</html>